package day240925;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/closeMessage")
public class CloseMessageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建一个Cookie，名为visited，值为任意字符串，有效期为5分钟（300秒）
        Cookie visitedCookie = new Cookie("visited", "yes");
        visitedCookie.setMaxAge(300); // 设置Cookie过期时间为5分钟
        visitedCookie.setPath("/"); // 确保整个应用都能访问到这个Cookie
        response.addCookie(visitedCookie); // 将Cookie添加到响应中

        // 重定向回WelcomeServlet
        response.sendRedirect(request.getContextPath() + "/WelcomeServlet");
    }
}
